﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CPGE
{

    public partial class Components_ActusSlider : System.Web.UI.UserControl
    {
        public string Titre { get; set; }
        public string ItemTitle { get; set; }
        public string SectionName { get; set; }
        public bool ShowTitle { get; set; }
        public bool WithLink = true;
        protected int Width;
        protected int Height = 130;
        public bool WithNav { get; set; }
        public BlocManager.BlocWidth Size = BlocManager.BlocWidth.Small;

        protected void Page_Load(object sender, EventArgs e)
        {
            SetTitle();
            if (Size.Equals(BlocManager.BlocWidth.Big))
                Width = 400;
            else Width = 200;

            Bloc.Attributes["class"] = "Bloc " + Size.ToString();
           
            

            //MainBloc.Attributes["class"] = "BlocMainContent" + Size.ToString();
            content.Text =((Literal) GetContent()).Text;
            
        }

        private Control GetContent()
        {
            try
            {
                return BlocManager.GetArticleSlider(Size, SectionName);                
            }
            catch (Exception exc)
            {
                Label lblErr = new Label();
                lblErr.Text = "Problème de récupération de données:" + exc.Message;
                return lblErr;
            }
        }

        private void SetTitle()
        {
            if (!ShowTitle)
            {
                BlocTitle.Visible = false;
            }
            else
            {
                if (Titre == null)
                     this.Title.Text = "À la une";
                else
                     this.Title.Text = Titre;                
            }
        }



    }
}
